package com.ai.common;

/**
 * @author: heJinQin
 * @create: 2024-04-06 14:52
 * @description:
 **/

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class LocalDateTimeDeserializer extends JsonDeserializer<LocalDateTime> {
    private static final DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
    private static final LocalDateTime minValue = LocalDateTime.MIN;
    private static final LocalDateTime maxValue = LocalDateTime.MAX;
    private static final long serialVersionUID = 1L; // Add a unique ID to the deserializer if needed

    @Override
    public LocalDateTime deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
        String value = p.getText();
        return LocalDateTime.parse(value, formatter); // Use the same formatter as in the serializer for consistency
    }
}

